home *** CD-ROM | disk | FTP | other *** search
- Path: news.zocalo.net!news
- From: Paul Hsieh <qed@xenon.chromatic.com>
- Newsgroups: comp.lang.c++,rec.games.programmer,alt.msdos.programmer,comp.programming
- Subject: Re: Young programmers read me.
- Date: Thu, 11 Apr 1996 20:55:30 -0700
- Organization: Zocalo Engineering - Berkeley, California, USA
- Message-ID: <316DD432.5B5B@xenon.chromatic.com>
- References: <4kj3rp$11d@news1.mnsinc.com> <1557.6675T1105T358@telecall.co.uk>
- NNTP-Posting-Host: paulh.chromatic.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- My personal feeling on coding style is that it should reflect what you
- are doing. To that end I try to use the latitude given to me by the
- ability to have arbitrary white space in my code to identify "scope".
- I think this was the entire intention of K&R when they designed C and
- gave their samples.
-
- > >: >if(something_happened)
- > >: >{
- > >: > do_something_else();
- > >: >}
- > >: >is_n't_it(); :)
-
- The code above is practically unreadable to me, because the lone "{"
- confuses me about where the actual scope begins and ends. Alternatively,
-
- if(something) {
- do_something_special(); // The do_something_special function
- } // endif
-
- Is_not_what_was_typed_above(); // This is called regardless.
-
- In this way, the beginning and end clause appear more symmetrical and
- each line is self describing in what they do. A single line that says
- "{" doesn't describe anything. It can't be commented beyond saying
- "// beginning of scope" which would be really redunant to be looking
- at sprinkled all over your code.
-
- > > Sure, I can understand that this might be a problem if you're
- > >still using edlin. :) This is really a personal preference issue and
- > >nobody is going to change anyone else's mind. My problem with the less
- > >space argument is that it implies that you don't comment your code either.
-
- I'll take the previous poster's personal preference over you *implication*
- any day. I'm a concise but descriptive camper myself. Code is something
- to be written and debugged. The less time I spend hitting the down arrow
- key or the pagedown key and the less time I spent staring at blank white
- space that tells me nothing, the better.
-
- > >Not to mention the fact that you might as well shove most of your code
- > >onto the same lines, only line-breaking when absolutely needed.
- >
- > >void foo(int i, char *list){int t;for(t=0;t<i;t++){printf("#%i",t);
- > >printf("%s\n",list[t]);}printf("%i total.\n",t);}
-
- I would prefer this code to the code above if it were better commented and
- used more descriptive tokens. If you write code in this form though, you
- have simply declared that the subtleties of how it works is unimportant and
- that you are highly confident of its functionality; its only good for the
- global symbol it defines. Perfectly acceptable, just comment it.
-
- > > Wow! Look at how much space that saved. I could put all my code
- > >in just two or three pages. :) I much prefer.
- >
- > There is a neat feature in Amos on the Amiga called "fold", well, really
- > it is a feature of the Amos editor, to pack functions or expand them as
- > you require.
-
- There are utilities for the PC for obfusticating and de-obfusticating your
- C-code as well. AN obfusticator is sitting on the WATCO
-
- --
- Paul Hsieh
- qed@xenon.chromatic.com
- Graphics Programmer
- Chromatic Research
-
- What I say and what my company says are not always the same thing
-